package cn.ming.wfchat.kit.third.location.viewholder;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;

import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.OnClick;
import cn.ming.wfchat.kit.R2;
import cn.ming.wfchat.kit.WfcWebViewActivity;
import cn.ming.wfchat.kit.annotation.EnableContextMenu;
import cn.ming.wfchat.kit.annotation.MessageContentType;
import cn.ming.wfchat.kit.conversation.ConversationFragment;
import cn.ming.wfchat.kit.conversation.message.model.UiMessage;
import cn.ming.wfchat.kit.conversation.message.viewholder.NormalMessageContentViewHolder;
import cn.wildfirechat.message.AnnouncementContent;

@MessageContentType({AnnouncementContent.class})
@EnableContextMenu
public class AnnouncementMessageContentViewHolder extends NormalMessageContentViewHolder {

    @BindView(R2.id.iv_img)
    ImageView ivImg;
    @BindView(R2.id.tv_title)
    TextView tvTitle;
    AnnouncementContent announcementContent;

    public AnnouncementMessageContentViewHolder(ConversationFragment fragment, RecyclerView.Adapter adapter, View itemView) {
        super(fragment, adapter, itemView);
    }

    @Override
    public void onBind(UiMessage message) {
        announcementContent = (AnnouncementContent) message.message.content;
        tvTitle.setText(announcementContent.getTitle());
        Glide.with(fragment).load(announcementContent.getCover())
                .apply(new RequestOptions().centerCrop()).into(ivImg);

    }

    @OnClick(R2.id.iv_img)
    public void onClick(View view) {
        WfcWebViewActivity.loadUrl(fragment.getActivity(), announcementContent.getTitle(), announcementContent.getArticleLink());
    }
}
